package com.zhss.redis.java;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * @Description TODO
 * @Author winston
 * @DateTime 2021/9/30
 */
public class LockDecrement {
	private Map<String, String> map = new HashMap<>();

	private ReadWriteLock rwl = new ReentrantReadWriteLock();

	private Lock readLock = rwl.readLock();
	private Lock writeLock = rwl.writeLock();

	private volatile boolean isUpdate;

	public void readWrite() {
		readLock.lock();
		if (!isUpdate) {
			readLock.unlock();
			writeLock.lock();
			map.put("xxx", "xxx");
			readLock.lock();
			writeLock.unlock();
		}

		Object obj = map.get("xxx");

		System.out.println(obj);
		readLock.unlock();

	}

	public static void main(String[] args) {
		LockDecrement lockDecrement = new LockDecrement();
		lockDecrement.readWrite();
	}
}
